package org.pvt.model;

import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.widget.CursorAdapter;
import android.widget.SimpleCursorAdapter;
import org.jetbrains.annotations.NotNull;

import static org.pvt.model.db.DBUtils.getReadableDB;

/**
 * @author Pavel Talanov
 */
public final class Event extends HasName {

    /*package*/ static String TABLE_NAME = "events";

    @NotNull
    public final CursorAdapter createCursorAdapter(@NotNull Activity activity) {
        SQLiteDatabase readableDatabase = getReadableDB(activity);
        Cursor cursor = readableDatabase.query(getTableName(), getFieldNames(), null, new String[]{}, null, null, null);
        activity.startManagingCursor(cursor);
        int[] to = {android.R.id.text1};
        String[] from = new String[]{NAME};
        return new SimpleCursorAdapter(activity, android.R.layout.simple_list_item_1, cursor, from, to);
    }

    @NotNull
    @Override
    public String getTableName() {
        return TABLE_NAME;
    }

    @NotNull
    public String getExtrasName() {
        return getTableName() + "_extra";
    }
}
